package com.huawei.secure.android.common.encrypt.utils;

import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import com.huawei.secure.android.common.encrypt.hash.PBKDF2;

public class RootKeyUtil {
    private static final int L = 10000;
    private static final int N = 16;
    private static final int O = 16;
    private byte[] M = null;

    private RootKeyUtil() {
    }

    public static RootKeyUtil newInstance(String str, String str2, String str3, String str4) {
        RootKeyUtil rootKeyUtil = new RootKeyUtil();
        rootKeyUtil.a(str, str2, str3, str4);
        return rootKeyUtil;
    }

    public static RootKeyUtil newInstance(String str, String str2, String str3, byte[] bArr) {
        RootKeyUtil rootKeyUtil = new RootKeyUtil();
        rootKeyUtil.a(str, str2, str3, bArr);
        return rootKeyUtil;
    }

    private void a(String str, String str2, String str3, String str4) {
        a(str, str2, str3, a.l(str4));
    }

    public byte[] getRootKey() {
        return (byte[]) this.M.clone();
    }

    public String getRootKeyHex() {
        return a.f(this.M);
    }

    private static boolean h(byte[] bArr) {
        return bArr.length >= 16;
    }

    private static boolean a(int i) {
        return i >= 16;
    }

    private void a(String str, String str2, String str3, byte[] bArr) {
        byte[] l = a.l(str);
        byte[] l2 = a.l(str2);
        byte[] l3 = a.l(str3);
        int a = a(l.length, l2.length, l3.length);
        if (a(a, bArr)) {
            char[] cArr = new char[a];
            for (int i = 0; i < a; i++) {
                cArr[i] = (char) ((l[i] ^ l2[i]) ^ l3[i]);
            }
            this.M = PBKDF2.pbkdf2(cArr, bArr, 10000, DnsConfig.MAX_CACHE_ENTRIES);
            return;
        }
        throw new IllegalArgumentException("key length must be more than 128bit.");
    }

    private int a(int i, int i2, int i3) {
        int i4;
        if (i2 < i) {
            i4 = i2;
        } else {
            i4 = i;
        }
        return i3 < i4 ? i3 : i4;
    }

    private boolean a(int i, byte[] bArr) {
        return a(i) & h(bArr);
    }
}
